import { useState, useEffect } from "react";
import "./index.less";
import { Input, message } from "antd";
import { request } from "../../../../../../../common/request";
import { urls } from "../../../../../../../common/urls";

const { TextArea } = Input;

function Welcome({profileList}: any) {
  const [welcomeText, setWelcomeText] = useState('');

  const handleSetWelcomeText = (e: any) => {
    setWelcomeText(e.target.value);
  }

  const submitWelcom = () => {
    request({
      method: "post",
      data: {
        method: urls.submitWelcom,
        content: welcomeText
      },
    }).then((res: any) => {
      message.success(res.msg);
    }).catch((err) => {
      message.error(err);
    });
  };

  useEffect(() => {
    setWelcomeText(profileList.welcome_words);
  }, [profileList]);

  return (
    <>
      <div className="welcome-page text-style">
        <TextArea
            className="welcome-textArea"
            style={{ resize: 'none' }}
            placeholder="请输入欢迎语"
            value={ welcomeText }
            onChange={ handleSetWelcomeText }
          />
        <div className="welcome-btn" onClick={ submitWelcom }>保存</div>
      </div>
    </>
  );
}

export default Welcome;
